/**
 * Created by zero on 2016/2/29.
 */

angular.module('shareserviceother', [])
  //第三方分享的service
  .factory('ShareServiceOther', function ($resource, $rootScope,$ionicActionSheet, ENV,Toast,ShareService) {

    return {

      //显示分享框
      showShareWindow : function(mm_id,type){
        var texts = [];
        var isWechatInstalled = ShareService.getIsWeChatInstalled();
        var isWeiBoInstalled = ShareService.getIsWeiBoInstalled();
        var isQqInstalled = ShareService.getIsQqInstalled();
        //alert("we" +isWechatInstalled+ "wb"+isWeiBoInstalled+"qq"+isQqInstalled);
        /*texts.push({text: "<img src='img/wechat-icon.png' height='50px'/><span>微信好友</span>"});
         texts.push({text: "<img src='img/wechat-icon.png' height='50px'/><span>微信好友</span>"});*/
        if(isWechatInstalled){
          texts.push({text: "<img class='share' src='img/wechat-icon.png' height='50px'/><span>微信好友</span>"});
          texts.push({text: "<img class='share' src='img/pyq-icon.png' height='50px'/><span>微信朋友圈</span>"});
        }
        if(isWeiBoInstalled){
          texts.push({text: "<img class='share' src='img/weibo-icon.png' height='50px'/><span>新浪微博</span>"});
        }
        if(isQqInstalled){
          texts.push({text: "<img class='share' src='img/qq-icon.png' height='50px'/><span>QQ好友</span>"});
        }
        //console.log(texts);

        if(type == "meeting"){
          $ionicActionSheet.show({
            cssClass: "share-popu",
            titleText : "分享到",
            buttons: texts,
            cancelText: "取 消",
            cancel: function () {/* 隐藏分享框*/},
            buttonClicked: function (index) {
              if(index==0){//分享到微信好友
                if(isWechatInstalled){
                  ShareService.shareMeetingToWeiXin(mm_id);
                }else{
                  if(isWeiBoInstalled){
                    ShareService.shareMeetingToWeiBo(mm_id);
                  }else{
                    if(isQqInstalled){
                      ShareService.shareMeetingToQQ(mm_id);
                    }else{

                    }
                  }
                }
                return true;
              }
              if(index==1){//分享到微信朋友圈
                if(isWechatInstalled){
                  ShareService.shareMeetingToWeiXinFriend(mm_id);
                }else{
                  if(isWeiBoInstalled && isQqInstalled){
                    ShareService.shareMeetingToQQ(mm_id);
                  }
                }
                return true;
              }
              if(index==2){//分享到新浪微博
                if(isWechatInstalled){
                  if(isWeiBoInstalled){
                    ShareService.shareMeetingToWeiBo(mm_id);
                  }else{
                    if(isQqInstalled){
                      ShareService.shareMeetingToQQ(mm_id);
                    }
                  }
                }
                return true;
              }
              if(index==3){//QQ好友
                if(isWechatInstalled && isWeiBoInstalled && isQqInstalled){
                  ShareService.shareMeetingToQQ(mm_id);
                }
                return true;
              }
            }
          });
        }else if(type == "home"){
          //分享酒窝
          $ionicActionSheet.show({
            cssClass: "share-popu",
            titleText : "分享到",
            buttons: texts,
            cancelText: "取 消",
            cancel: function () {/* 隐藏分享框*/},
            buttonClicked: function (index) {
              if(index==0){//分享到微信好友
                if(isWechatInstalled){
                  ShareService.shareHomeToWeiXin(mm_id);
                }else{
                  if(isWeiBoInstalled){
                    ShareService.shareHomeToWeiBo(mm_id);
                  }else{
                    if(isQqInstalled){
                      ShareService.shareHomeToQQ(mm_id);
                    }else{

                    }
                  }
                }
                return true;
              }
              if(index==1){//分享到微信朋友圈
                if(isWechatInstalled){
                  ShareService.shareHomeToWeiXinFriend(mm_id);
                }else{
                  if(isWeiBoInstalled && isQqInstalled){
                    ShareService.shareHomeToQQ(mm_id);
                  }
                }
                return true;
              }
              if(index==2){//分享到新浪微博
                if(isWechatInstalled){
                  if(isWeiBoInstalled){
                    ShareService.shareHomeToWeiBo(mm_id);
                  }else{
                    if(isQqInstalled){
                      ShareService.shareHomeToQQ(mm_id);
                    }
                  }
                }
                return true;
              }
              if(index==3){//QQ好友
                if(isWechatInstalled && isWeiBoInstalled && isQqInstalled){
                  ShareService.shareHomeToQQ(mm_id);
                }
                return true;
              }
            }
          });
        }
      }

    }

  });



